<?php use_helper('Object', 'Validation', 'ObjectAdmin', 'I18N', 'Date') ?>
<title><?= $sf_response->getTitle() ?></title>
<?php use_stylesheet('/sf/sf_admin/css/main') ?>

<div id="sf_admin_container">
<div id="sf_admin_header">
<?php if ($sf_request->hasError('approve')): ?>
<div class="form-errors">
  <h2><?php echo __('Could not approve') ?></h2>
  <ul>
    <li><?php echo __($sf_request->getError('approve')) ?></li>
  </ul>
</div>
<?php elseif ($sf_request->hasError('reject')): ?>
<div class="form-errors">
  <h2><?php echo __('Could not reject') ?></h2>
  <ul>
    <li><?php echo __($sf_request->getError('reject')) ?></li>
  </ul>
</div>
<?php elseif ($sf_user->hasFlash('notice')): ?>
<div class="save-ok">
 <h2><?php echo __($sf_user->getFlash('notice')) ?></h2>
</div>
<?php endif; ?>
</div>
<? if ($module=='BOM') {?>
<h1>BOM Approval List</h1>
<div id="sf_admin_content">
<table id ='added_components' "cellspacing="0" class="sf_admin_list">
<thead>
<tr>
      <th id="sf_admin_list_th_productcode" >BOM Number
              </th>
      <th id="sf_admin_list_th_description" >Project
              </th>
      <th id="sf_admin_list_th_description" >Status
              </th>
      <th id="sf_admin_list_th_description" >MR
              </th>       
      <th id="sf_admin_list_th_description">Comp List
              </th>
      <th id="sf_admin_list_th_description">Approver List
              </th>
      <th id="sf_admin_list_th_description">Action</th>
</tr>
</thead>
<!--show component here-->
<?php  
    foreach ($ObjectneedApprovalList as $key=>$object) {  ?>
        <tr class="sf_admin_row_<?php echo $key%2?>">
            <td><?echo link_to($object->getWono(), 'bom/view?id='.$object->getId())?></td>
            <td><?echo $object->getProject(); ?></td>
            <td><? if ($object->getReviseId()) echo "Revise"; else echo "New"; ?></td>
            <td><?echo link_to("view MR", 'mr/viewFromBom?id='.$object->getId())?></td>
            <td><?php echo link_to($object->getComponentgroupId() ? image_tag('/sf/sf_admin/images/list.png', array('alt' => 'List', 'title' => 'List')):  __('-'), 'component/SLListModuleGroup?componentgroup_id='.$object->getComponentgroupId().'&Authentication=VIEW_BOM&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_BOM~3authenticationSub~4PR_APPROVE_MR~3mod~4BOM~3backURL~4&titleqty=Qty need'); ?></td>
            <td>
            <?
            $c = new Criteria();
            $c->add(ApprovalPeer::TYPE , CommonValues::$gApprovalType['key']['BOM']);
            $c->add(ApprovalPeer::OBJECT_ID , $object->getId());
            $c->addAscendingOrderByColumn(ApprovalPeer::ID);
            $approvals = ApprovalPeer::doSelect($c);
            if ($approvals && count($approvals)){
                foreach ($approvals as $approval){
                    $user = sfGuardUserPeer::retrieveByPK($approval->getUserId());
                    if ($user){
                        $grNames = $user->getGroupNames();
                        echo '<p>';
                        echo isset($grNames[0])? $grNames[0]: '';
                        echo ': '.$user->getFullname();
                        echo '</p>';
                    }
                }
            }
?>
            </td>
            <td>
                
<ul class="sf_admin_actions">
  <li><?php echo button_to(__('Approve'), 'approval/ApproveObject?authenticationMain=APPROVE_BOM&authenticationSub=PR_APPROVE_MR&mod=BOM&id='.$object->getId().'&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_BOM~3authenticationSub~4PR_APPROVE_MR~3mod~4BOM~3backURL~4', array (
  'class' => 'sf_admin_action_approve',
  'confirm' => __('Are you sure you want to approve this BOM?'),
)) ?></li>
  <li><?php echo button_to(__('Reject'), 'approval/RejectObject?authenticationMain=APPROVE_BOM&authenticationSub=PR_APPROVE_MR&mod=BOM&id='.$object->getId().'&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_BOM~3authenticationSub~4PR_APPROVE_MR~3mod~4BOM~3backURL~4', array (
  'class' => 'sf_admin_action_reject',
)) ?></li>
    </ul>
            
        
    </td>
        </tr>
<?php } ?>
</table>

</div>
<? } ?>

<? if ($module=='MRSUB') {?>
<h1>MR Sub Approval List</h1>
<div id="sf_admin_content">
<table id ='added_components' "cellspacing="0" class="sf_admin_list">
<thead>
<tr>
      <th id="sf_admin_list_th_productcode" >MR Number
              </th>
      <th id="sf_admin_list_th_description" >Category
              </th>       
      <th id="sf_admin_list_th_description">Comp List
              </th>
      <th id="sf_admin_list_th_description">Approver List
      
      <th id="sf_admin_list_th_description">Action</th>
</tr>
</thead>
<!--show component here-->
<?php  
    foreach ($ObjectneedApprovalList as $key=>$object) {  ?>
        <tr class="sf_admin_row_<?php echo $key%2?>">            
            <td><?echo link_to($object->getMrno(), 'mr2/view?id='.$object->getId())?></td>
            <td><?echo CommonValues::$gMRCategory['value'][$object->getCategory()] ?></td>
            <td><?php echo link_to($object->getComponentgroupId() ? image_tag('/sf/sf_admin/images/list.png', array('alt' => 'List', 'title' => 'List')):  __('-'), 'component/SLListModuleGroup?componentgroup_id='.$object->getComponentgroupId().'&Authentication=VIEW_MRSUB&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_MRSUBSTK~3authenticationSub~4APPROVE_MRSUBFTR~3mod~4MRSUB~3backURL~4&titleqty=Qty to request&titleqty2=Min stock (%)') ?></td>
            
            <td>
            <?
            $c = new Criteria();
            $c->add(ApprovalPeer::TYPE , CommonValues::$gApprovalType['key']['MRSUB']);
            $c->add(ApprovalPeer::OBJECT_ID , $object->getId());
            $c->addAscendingOrderByColumn(ApprovalPeer::ID);
            $approvals = ApprovalPeer::doSelect($c);
            if ($approvals && count($approvals)){
                foreach ($approvals as $approval){
                    $user = sfGuardUserPeer::retrieveByPK($approval->getUserId());
                    if ($user){
                        $grNames = $user->getGroupNames();
                        echo '<p>';
                        echo isset($grNames[0])? $grNames[0]: '';
                        echo ': '.$user->getFullname();
                        echo '</p>';
                    }
                }
            }
?>
            </td>
            <td>
                
<ul class="sf_admin_actions">
  <li><?php echo button_to(__('Approve'), 'approval/ApproveObject?authenticationMain=APPROVE_MRSUBSTK&authenticationSub=APPROVE_MRSUBFTR&mod=MRSUB&id='.$object->getId().'&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_MRSUBSTK~3authenticationSub~4APPROVE_MRSUBFTR~3mod~4MRSUB~3backURL~4', array (
  'class' => 'sf_admin_action_approve',
  'confirm' => __('Are you sure you want to approve this MR?'),
)) ?></li>
  <li><?php echo button_to(__('Reject'), 'approval/RejectObject?authenticationMain=APPROVE_MRSUBSTK&authenticationSub=APPROVE_MRSUBFTR&mod=MRSUB&id='.$object->getId().'&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_MRSUBSTK~3authenticationSub~4APPROVE_MRSUBFTR~3mod~4MRSUB~3backURL~4', array (
  'class' => 'sf_admin_action_reject',
)) ?></li>
    </ul>
            </td></tr>
<?php } ?>
</table>

</div>
<? } ?>

<? if ($module=='MRRAW') {?>
<h1>MR Raw Approval List</h1>
<div id="sf_admin_content">
<table id ='added_components' "cellspacing="0" class="sf_admin_list">
<thead>
<tr>
      <th id="sf_admin_list_th_productcode" >MR Number
              </th>
      <th id="sf_admin_list_th_description" >Category
              </th>       
      <th id="sf_admin_list_th_description">Comp List
              </th>
      <th id="sf_admin_list_th_description">Approver List
      
      <th id="sf_admin_list_th_description">Action</th>
</tr>
</thead>
<!--show component here-->
<?php  
    foreach ($ObjectneedApprovalList as $key=>$object) {  ?>
        <tr class="sf_admin_row_<?php echo $key%2?>">            
            <td><?echo link_to($object->getMrno(), 'mr3/view?id='.$object->getId())?></td>
            <td><?echo CommonValues::$gMRCategory['value'][$object->getCategory()] ?></td>
            <td><?php echo link_to($object->getComponentgroupId() ? image_tag('/sf/sf_admin/images/list.png', array('alt' => 'List', 'title' => 'List')):  __('-'), 'component/SLListModuleGroup?componentgroup_id='.$object->getComponentgroupId().'&Authentication=VIEW_MRRAW&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_MRRAW~3authenticationSub~4PR_APPROVE_MRRAW~3mod~4MRRAW~3backURL~4&titleqty=Qty to request') ?></td>
            
            <td>
            <?
            $c = new Criteria();
            $c->add(ApprovalPeer::TYPE , CommonValues::$gApprovalType['key']['MRRAW']);
            $c->add(ApprovalPeer::OBJECT_ID , $object->getId());
            $c->addAscendingOrderByColumn(ApprovalPeer::ID);
            $approvals = ApprovalPeer::doSelect($c);
            if ($approvals && count($approvals)){
                foreach ($approvals as $approval){
                    $user = sfGuardUserPeer::retrieveByPK($approval->getUserId());
                    if ($user){
                        $grNames = $user->getGroupNames();
                        echo '<p>';
                        echo isset($grNames[0])? $grNames[0]: '';
                        echo ': '.$user->getFullname();
                        echo '</p>';
                    }
                }
            }
?>
            </td>
            <td>
                
<ul class="sf_admin_actions">
  <li><?php echo button_to(__('Approve'), 'approval/ApproveObject?authenticationMain=APPROVE_MRRAW&authenticationSub=PR_APPROVE_MRRAW&mod=MRRAW&id='.$object->getId().'&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_MRRAW~3authenticationSub~4PR_APPROVE_MRRAW~3mod~4MRRAW~3backURL~4', array (
  'class' => 'sf_admin_action_approve',
  'confirm' => __('Are you sure you want to approve this MR?'),
)) ?></li>
  <li><?php echo button_to(__('Reject'), 'approval/RejectObject?authenticationMain=APPROVE_MRRAW&authenticationSub=PR_APPROVE_MRRAW&mod=MRRAW&id='.$object->getId().'&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_MRRAW~3authenticationSub~4PR_APPROVE_MRRAW~3mod~4MRRAW~3backURL~4', array (
  'class' => 'sf_admin_action_reject',
)) ?></li>
    </ul>
            </td>
        </tr>
<?php } ?>
</table>

</div>
<? } ?>

<? if ($module=='PO') {?>
<h1>PO Approval List</h1>
<div id="sf_admin_content">
<table id ='added_components' "cellspacing="0" class="sf_admin_list">
<thead>
<tr>
      <th id="sf_admin_list_th_productcode" >PO Number
              </th>
      <th id="sf_admin_list_th_description" >MR
              </th>       
      <th id="sf_admin_list_th_description" >Category
              </th>       
      <th id="sf_admin_list_th_description">Comp List
              </th>
      <th id="sf_admin_list_th_description">Approver List
      
      <th id="sf_admin_list_th_description">Action</th>
</tr>
</thead>
<!--show component here-->
<?php  
    foreach ($ObjectneedApprovalList as $key=>$object) {  ?>
        <tr class="sf_admin_row_<?php echo $key%2?>">            
            <td><?echo link_to($object->getPono(), 'po/view?id='.$object->getId())?></td>
            <td><?
                $MRId = $object->getMrno();
                $mr = null;
                $compCate =$object->getCompcategory();
                if ($compCate == CommonValues::$gCompCategory['key']['Main Component']) {
                    $mr = MRPeer::retrieveByPK($MRId);
                } elseif ($compCate == CommonValues::$gCompCategory['key']['Sub Component']) {
                    $mr = MR2Peer::retrieveByPK($MRId);
                } else {
                    $mr = MR3Peer::retrieveByPK($MRId);
                }

                echo $mr->getMrno();

                if ($compCate == CommonValues::$gCompCategory['key']['Main Component']) {
                    echo ':'.$mr->getProject();
                }
            ?></td>
            <td><?echo CommonValues::$gMRCategory['value'][$object->getCategory()] ?></td>
            <td><?php echo link_to($object->getComponentgroupId() ? image_tag('/sf/sf_admin/images/list.png', array('alt' => 'List', 'title' => 'List')):  __('-'), 'component/SLListPOGroup?componentgroup_id='.$object->getComponentgroupId().'&Authentication=VIEW_PO&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_PO~3authenticationSub~4PR_APPROVE_PO~3mod~4PO~3backURL~4') ?></td>
            
            <td>
            <?
            $c = new Criteria();
            $c->add(ApprovalPeer::TYPE , CommonValues::$gApprovalType['key']['PO']);
            $c->add(ApprovalPeer::OBJECT_ID , $object->getId());
            $c->addAscendingOrderByColumn(ApprovalPeer::ID);
            $approvals = ApprovalPeer::doSelect($c);
            if ($approvals && count($approvals)){
                foreach ($approvals as $approval){
                    $user = sfGuardUserPeer::retrieveByPK($approval->getUserId());
                    if ($user){
                        $grNames = $user->getGroupNames();
                        echo '<p>';
                        echo isset($grNames[0])? $grNames[0]: '';
                        echo ': '.$user->getFullname();
                        echo '</p>';
                    }
                }
            }
?>
            </td>
            <td>
                
<ul class="sf_admin_actions">
  <li><?php echo button_to(__('Approve'), 'approval/ApproveObject?authenticationMain=APPROVE_PO&authenticationSub=PR_APPROVE_PO&mod=PO&id='.$object->getId().'&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_PO~3authenticationSub~4PR_APPROVE_PO~3mod~4PO~3backURL~4', array (
  'class' => 'sf_admin_action_approve',
  'confirm' => __('Are you sure you want to approve this PO?'),
)) ?></li>
  <li><?php echo button_to(__('Reject'), 'approval/RejectObject?authenticationMain=APPROVE_PO&authenticationSub=PR_APPROVE_PO&mod=PO&id='.$object->getId().'&backURL=approval~1ListApprovalObject~2authenticationMain~4APPROVE_PO~3authenticationSub~4PR_APPROVE_PO~3mod~4PO~3backURL~4', array (
  'class' => 'sf_admin_action_reject',
)) ?></li>
    </ul>
            </td></tr>
<?php } ?>
</table>

</div>
<? } ?>
</div>